(*****************************************************************************
 * Delphi Plug-in Framework (DPF)
 * Copyright (C) 2006-2007 Tao Yuan
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the
 * License at http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.                                                               }
 *
 * The Initial Developer of the Original Code is Tao Yuan. Portions created by
 * Tao Yuan are Copyright (C) Tao Yuan (taoy.cn att gmail dott com)
 * All rights reserved.
 *****************************************************************************)
 
unit RDStandardPluginService;

interface

uses
  Rcl,
  RdClasses, RDPluginService, RDPluginManager, RDPluginRegistry;

type
  TPluginService = class(TRdInterfacedObject, IPluginService)
  private
    FPluginManager: TPluginManager;
  protected
    function ActivePlugin(APluginId: string): IPluginInfo; stdcall;
    procedure DeactivatePlugin(APluginID: string);
    function GetExtensionPoint(APluginInfo: IPluginInfo; APointId: string):
        IExtensionPoint; stdcall;
    function GetPlugin(APluginId: string): IPluginInfo; stdcall;
    function GetRegistry: IPluginRegistry; stdcall;
    function isBadPlugin(descr: IPluginDescriptor): Boolean; stdcall;
    function isPluginActivated(descr: IPluginDescriptor): boolean; stdcall;
    function isPluginActivating(descr: IPluginDescriptor): boolean; stdcall;
    function isPluginEnabled(descr: IPluginDescriptor): boolean; stdcall;
   
  public
    constructor Create(APluginManager: TPluginManager);
    destructor Destroy; override;
  end;

implementation

constructor TPluginService.Create(APluginManager: TPluginManager);
begin
  inherited Create;
  FPluginManager := APluginManager;
  FPluginManager.PluginService := Self;
end;

destructor TPluginService.Destroy;
begin
  try
    FPluginManager.Free;
  finally

  end;
  inherited;
end;

function TPluginService.ActivePlugin(APluginId: string): IPluginInfo;
begin
  Result := FPluginManager.activatePlugin(APluginId);
end;

procedure TPluginService.DeactivatePlugin(APluginID: string);
begin
  FPluginManager.deactivatePlugin(APluginID);
end;

function TPluginService.GetExtensionPoint(APluginInfo: IPluginInfo; APointId:
    string): IExtensionPoint;
begin
  Result := FPluginManager.getRegistry.getExtensionPoint(
      APluginInfo.Descriptor.getId,
      APointId)
end;

function TPluginService.GetPlugin(APluginId: string): IPluginInfo;
begin
  Result := FPluginManager.getPlugin(APluginId);
end;

function TPluginService.GetRegistry: IPluginRegistry;
begin
  Result := FPluginManager.getRegistry;
end;

function TPluginService.isBadPlugin(descr: IPluginDescriptor): Boolean;
begin
  Result := FPluginManager.isBadPlugin(descr);
end;

function TPluginService.isPluginActivated(descr: IPluginDescriptor): boolean;
begin
  Result := FPluginManager.isPluginActivated(descr);
end;

function TPluginService.isPluginActivating(descr: IPluginDescriptor): boolean;
begin
  Result := FPluginManager.isPluginActivating(descr);
end;

function TPluginService.isPluginEnabled(descr: IPluginDescriptor): boolean;
begin
  Result := FPluginManager.isPluginEnabled(descr);
end;

end.
